import json

from devicetest.api import Asserts
from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Memorandum


class PreTest_RK3568_Tooling_Memorandum_0700(TestCase, Memorandum):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 1.进入桌面-备忘录应用，长按笔记，点击置顶按钮
    # 2.查看笔记状态
    # 预期结果：
    # 1.长按笔记，可单选或多选，置顶按钮正常
    # 2.笔记被置放到最上方，且有置顶标识

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):
        Step('步骤1：进入桌面-备忘录应用，长按笔记，点击置顶按钮')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.touchByText(self.Phone1, '蛋糕做法', mode='LONG')
        Step('预期结果1：点击搜素框可唤醒键盘，显示无遮挡，搜索显示结果与搜索框输入的关键词一致')
        # 键盘
        CommonOH.checkIfTextExist(self.Phone1, '置顶')
        CommonOH.checkIfTextExist(self.Phone1, '多选')
        Step('步骤2：点击置顶按钮，查看笔记状态')
        CommonOH.click(self.Phone1, **self.topping_menu)
        CommonOH.wait(self.Phone1, 0.5)
        cake_bounds = json.loads(CommonOH.getWidgetProperties(self.Phone1, '蛋糕做法'))['bounds']
        travel_bounds = json.loads(CommonOH.getWidgetProperties(self.Phone1, '旅游心得'))['bounds']
        Asserts.assert_greater(travel_bounds['topY'], cake_bounds['bottomY'])

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
